package com.momoauth.common.core.result;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.momoauth.common.core.enumeration.ResultCodeEnum;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResponseResurt {

    private Integer code;
    private String msg;
    private Object data;

    /**
     * 统一返回
     */

    // 统一成功返回
    public static ResponseResurt success() {
        ResponseResurt resurt = new ResponseResurt();
        resurt.setCode(ResultCodeEnum.SUCCESS.getCode());
        resurt.setMsg(ResultCodeEnum.SUCCESS.getMsg());
        return resurt;
    }

    // 统一错误返回
    public static ResponseResurt error() {
        ResponseResurt resurt = new ResponseResurt();
        resurt.setCode(ResultCodeEnum.ERROR.getCode());
        resurt.setMsg(ResultCodeEnum.ERROR.getMsg());
        return resurt;
    }

    // 设置返回结果
    public static ResponseResurt setResult(ResultCodeEnum codeEnum) {
        ResponseResurt resurt = new ResponseResurt();
        resurt.setCode(codeEnum.getCode());
        resurt.setMsg(codeEnum.getMsg());
        return resurt;
    }

    /**
     * 链式编程
     */

    // 自定义状态码
    public ResponseResurt code(Integer code) {
        this.setCode(code);
        return this;
    }

    // 自定义状态信息
    public ResponseResurt msg(String msg) {
        this.setMsg(msg);
        return this;
    }

    // 自定义返回数据
    public ResponseResurt data(Object data) {
        this.setData(data);
        return this;
    }
}
